{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<!--<link href="{__STATIC__}/home/other/formSelects-v4.css" rel="stylesheet" />-->
<!--<script src="{__STATIC__}/home/other/jquery.min.js"></script>-->
<!--<script src="{__STATIC__}/home/other/formSelects-v4.min.js"></script>-->
<style>
    .layui-tree-entry {
        font-size: 15px;
        line-height: 24px
    }

    .layui-tree-set {
        padding: 2px 0
    }

    .layui-tree-iconClick .layui-icon {
        color: #1E9FFF
    }

    .layui-icon layui-icon-file {
        font-size: 16px;
    }

    .layui-tree-icon {
        height: 15px;
        width: 15px;
        text-align: center;
        border: 1px solid #1E9FFF;
        color: #1E9FFF
    }

    .layui-tree-line .layui-tree-set .layui-tree-set:after {
        top: 18px;
    }

    .tree-left {
        width: 200px;
        float: left;
        height: calc(100% - 30px);
        overflow: scroll;
        border: 1px solid #eeeeee;
        background-color: #FAFAFA;
        padding: 12px 12px 12px 5px;
    }

    .tree-left h3 {
        font-size: 16px;
        height: 30px;
        padding-left: 10px;
        font-weight: 800
    }

    .gougu-upload-files {
        background-color: #ffffff;
        border: 1px solid #e4e7ed;
        color: #c0c4cc;
        cursor: not-allowed;
        padding: 0 12px;
        width: 180px;
        box-sizing: border-box;
        display: inline-block;
        font-size: inherit;
        height: 38px;
        line-height: 35px;
        margin-right: 8px;
        border-radius: 2px;
    }

    .gougu-upload-tips {
        color: #969696
    }

    .layui-form-item {
        margin-bottom: 8px;
    }

    .layui-input-block {
        min-height: 24px;
    }
</style>
<div class="layui-col-lg12 layui-col-md12 layui-col-sm12">
    <!--    <div class="layui-col-lg2 layui-col-md2 layui-col-sm2 layui-col-xl2 layui-col-sm2 layui-col-xs2 layui-padding-2">-->
    <!--        <h3>物料分类</h3>-->
    <!--        <div id="ID-tree-demo-showLine"></div>-->
    <!--    </div>-->
    <!--    <div class="layui-col-lg10 layui-col-md10 layui-col-xl10 layui-col-sm10 layui-col-sm10 layui-col-xs10">-->
    <div class="">
        <form class="layui-form gg-form-bar border-t border-x">
            <!--            <div class="layui-input-inline" style="width:500px;">-->
            <!--                <input type="text" name="keywords" placeholder="编码/品牌/品名/型号/订货号/税收编码/采购合同" class="layui-input" autocomplete="off"/>-->
            <!--            </div>-->
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="brand" placeholder="品牌" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="mdName" placeholder="品名" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="specs" placeholder="型号" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="buyCode" placeholder="订货号" class="layui-input" autocomplete="off"/>
            </div>
<!--            <div class="layui-input-inline" style="width:300px;">-->
<!--                <input type="text" name="taxCode" placeholder="税收编码" class="layui-input" autocomplete="off"/>-->
<!--            </div>-->
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="cght" placeholder="采购合同" class="layui-input" autocomplete="off"/>
            </div>
<!--            <div class="layui-input-inline" style="width:300px;">-->
<!--                <input type="text" name="pName" placeholder="供应商" class="layui-input" autocomplete="off"/>-->
<!--            </div>-->
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="xsHt" placeholder="销售合同" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="xsdwName" placeholder="销售单位" class="layui-input" autocomplete="off"/>
            </div>
<!--            <div class="layui-input-inline" style="width:300px;">-->
<!--                <input type="text" name="cgrkd" placeholder="采购入库单" class="layui-input" autocomplete="off"/>-->
<!--            </div>-->
            <!--            <div class="layui-input-inline" style="width:300px;">-->
            <!--                <select name="warehouse_id" lay-search xm-select="warehouse_id" lay-filter="warehouse_id">-->
            <!--                    <option value="">仓库</option>-->
            <!--                    {volist name='warehouseList' id='wl'}-->
            <!--                    <option value="{$wl.id}">{$wl.name}</option>-->
            <!--                    {/volist}-->
            <!--                </select>-->
            <!--            </div>-->
<!--            <div class="layui-input-inline" style="width:300px;">-->
<!--                <input type="text" name="times" placeholder="入库时间" id="times" readonly class="layui-input" autocomplete="off"/>-->
<!--            </div>-->
            <input type="text" style="display: none" name="type" id="seType" value="" class="layui-input"
                   autocomplete="off">
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="hsContract" placeholder="货商合同" class="layui-input" autocomplete="off"/>
            </div>
            <div class="layui-input-inline" style="width:150px;">
                <button class="layui-btn layui-btn-normal" lay-submit="" id="webf" lay-filter="webformIndex"><i
                        class="layui-icon layui-icon-search mr-1"></i>搜索
                </button>
                <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
            </div>
        </form>
        <div class="p-3">
            <div>
                <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <!--    <a class="layui-btn layui-btn-sm layui-btn-normal " target="_blank" href="{:url('exportData')}">导出</a>-->
</script>
<script type="text/html" id="actionBar">

</script>
<script type="text/html" id="lockBar">
    <a href="javascript:" lay-event="seeLock">{{d.lockNum}}</a>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script type="text/javascript">
    // formSelects.render('warehouse_id');
    // formSelects.btns('warehouse_id',[]);
    // formSelects.on('warehouse_id',function (id,data) {
    //     let ids=[];
    //     data.forEach(function (item,index) {
    //         ids.push(item.value)
    //     })
    //        getLocal(ids);
    // },true)

</script>
<script>
    const moduleInit = ['tool'];

    function gouguInit() {
        var treeTable = layui.treeTable, tool = layui.tool, form = layui.form;
        var upload = layui.upload;
        var tableIns = treeTable.render({
            elem: '#treeTable'
            , url: "{:url('index')}"
            , toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports']
            , tree: { // treeTable 特定属性集
                customName: {name: 'name'},
                data: {},
                view: {showIcon: false},
                async: {},
                callback: {}
            }
            , cellMinWidth: 80
            , cols: [[
                // {type: 'checkbox', fixed: 'left'},
                // {fixed: 'left', field: 'id', title: 'ID', unresize: true, hide: true}
                // ,{field: 'id', width: 80, title: 'ID号', align: 'center'}
                // , {field: 'checkTime', title: '出库时间'}
                // , {field: 'typeName', title: '分类'}
                // , {field: 'bar_code', title: '编码'}
                // , {field: 'mdName', title: '物料名称'}
                , {field: 'brand', title: '品牌'}
                , {field: 'mdName', title: '品名'}
                , {field: 'specs', title: '型号'}
                , {field: 'buyCode', title: '订货号'}

                // , {field: 'taxCode', title: '税收编码'}
                , {field: 'unit', title: '单位'}
                // , {field: 'bjNum', title: '采购数量'}
                , {field: 'hasNum', title: '库存数量'}
                // , {field: 'lockNum', title: '已锁定数量',toolbar:'#lockBar'}
                // , {field: 'canUse', title: '可用数量'}
                , {field: 'bjPrice', title: '单价'}
                // , {field: 'lockNum', title: '占用数量',toolbar:'#lockBar'}
                , {field: 'kcMoney', title: '库存金额'}
                // , {field: 'pName', title: '供应商'}
                , {field: 'saleContractOrder', title: '采购合同'}
                , {field: 'hsContract', title: '货商合同'}
                , {field: 'xsHt', title: '销售合同'}
                , {field: 'stockOrderNum', title: '入库单号'}
                , {field: 'xsdwName', title: '销售单位'}
                , {field: 'cgmxRemark', title: '备注'}


                // , {title: '操作',fixed: 'right',width: 200,  align: 'center'
                //     , toolbar: '#actionBar'
                // }
            ]]
            , page: true,
            limits: [10, 20, 50, 80, 100, 200, 500, 1000, 2000, 5000, 10000],
        });
        //监听搜索提交
        form.on('submit(webformIndex)', function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //表头工具栏事件
        // $('.add-menu').on('click', function () {
        //     tool.side("/home/BomForm/add");
        //     return;
        // });

        //操作按钮
        treeTable.on('tool(treeTable)', function (obj) {
            console.log(obj);
            if (obj.event === 'add') {
                // tool.side('/home/BomForm/add?pid=' + obj.data.id);
                return;
            }
            if (obj.event === 'edit') {
                // tool.side('/home/BomForm/add?id=' + obj.data.id);
                return;
            }
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    // tool.delete("/home/BomForm/delete", {id: obj.data.id}, callback);
                    layer.close(index);
                });
            }
            if (obj.event === 'forbid') {
                layer.confirm('确定要禁用吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            tableIns.reload();
                        }
                    }
                    // tool.post("/home/BomForm/doCheck", { id: obj.data.id,status: 2}, callback);
                    layer.close(index);
                });
            }
            if (obj.event === 'resume') {
                layer.confirm('确定要启用吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            tableIns.reload();
                        }
                    }
                    // tool.post("/home/BomForm/doCheck", { id: obj.data.id,status: 1}, callback);
                    layer.close(index);
                });
            }
        });
        treeTable.on('toolbar(treeTable)', function (obj) {
            var checkStatus = treeTable.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch (obj.event) {
                case 'add':
                    break;
                case 'dels':
                    var data = checkStatus.data;
                    var ids = []
                    if (data.length) {
                        data.forEach(function (value, index) {
                            console.log('value', value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            // tool.delete("/home/BomForm/delete", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    } else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'import':

                    break;

            }
            ;
        })
        var tree = layui.tree;
        $.ajax({
            url: "/home/api/getMaterial_type",
            type: 'post',
            success: function (res) {
                //仅节点左侧图标控制收缩
                tree.render({
                    elem: '#ID-tree-demo-showLine',
                    data: res.data,
                    onlyIconControl: true,  //是否仅允许节点左侧图标控制展开收缩
                    click: function (obj) {
                        //layer.msg(JSON.stringify(obj.data));
                        type_id = obj.data.id
                        // tableIns.reload({
                        //     where: {type: obj.data.id}
                        //     ,page:{curr:1}
                        // });
                        $("#seType").val(type_id)
                        $("#webf").click()
                        // $('[name="keywords"]').val('');
                        // $('[name="status"]').val('');
                        // $('[name="type"]').val('');
                        layui.form.render('select');
                    }
                });
            }
        })

        layui.laydate.render({
                elem:'#times',
                range:'~'
            }
        )
        treeTable.on('tool(treeTable)', function (obj) {
            console.log('gggg',obj)
            switch (obj.event) {
                case 'seeLock':
                    let url="seeLock?id="+obj.data.id;
                    tool.side(url)
                    break
            }
            ;
        })
    }
    function testaa(obj) {
        console.log('obj',obj)
    }
    // function getLocal(id) {
    //     $("#locator").empty();
    //         if (id.length){
    //             ids=id.join(',')
    //             var optionStr="<option value=''>请选择数据</option>";
    //             $.ajax({
    //                 url:'/home/api/getWarHoseDetail',
    //                 type:'post',
    //                 dataType:'json',
    //                 data:{id:ids},
    //                 success:function (res) {
    //                     if (res.code==0){
    //                         let data=res.data;
    //                         for(var i=0;i<data.length;i++){
    //                             optionStr+=" <option value='"+data[i].id+"'>"+data[i].name+"</option>";
    //                         }
    //                     }else {
    //                     }
    //                     $("#locator").append(optionStr);
    //                     formSelects.render('locator');
    //                     formSelects.btns('locator',[]);
    //                 }
    //
    //             })
    //         }else {
    //             $("#locator").append(" <option value=''>请选先选择仓库</option>");
    //             formSelects.render('locator');
    //             formSelects.btns('locator',[]);
    //         }
    //
    //
    // }

</script>
{/block}
<!-- /脚本 -->